//
//  LTThemeView.m
//  LocalTravel
//
//  Created by zheng ji on 14-2-25.
//  Copyright (c) 2014年 jxw. All rights reserved.
//

#import "LTThemeView.h"
#import "LTTheme.h"
@interface LTThemeView ()
{
    
    UITableView* _tableTheme;
    CGRect _frame;
   
    
    
}
@end
@implementation LTThemeView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        _frame=frame;
        [self initTableTheme];
    }
    return self;
}
-(void)initTableTheme{
    /*
    self.themeArray=[NSArray arrayWithObjects:[LTTheme initWith:@"0" name:@"不限"],
                 [LTTheme initWith:@"1" name:@"休闲"],
                 [LTTheme initWith:@"2" name:@"滑雪"],
                 [LTTheme initWith:@"3" name:@"避暑"],
                 [LTTheme initWith:@"4" name:@"文化游"],
                 [LTTheme initWith:@"5" name:@"登山"],
                 [LTTheme initWith:@"6" name:@"游船"],
                 [LTTheme initWith:@"7" name:@"漂流"],
                 [LTTheme initWith:@"8" name:@"探险"],
                 [LTTheme initWith:@"9" name:@"拓展训练"],
                 [LTTheme initWith:@"10" name:@"温泉"],
                 [LTTheme initWith:@"11" name:@"演出"],
                 [LTTheme initWith:@"12" name:@"疗养"],
                 [LTTheme initWith:@"13" name:@"生态旅游"],
                     [LTTheme initWith:@"14" name:@"户外拓展"],
                     [LTTheme initWith:@"15" name:@"园林景区"],
                     [LTTheme initWith:@"16" name:@"水乡"],
                     [LTTheme initWith:@"17" name:@"古镇"],
                     [LTTheme initWith:@"18" name:@"农家乐"],
                     [LTTheme initWith:@"19" name:@"海滨海岛"],
                     [LTTheme initWith:@"20" name:@"主题乐园"],
                     [LTTheme initWith:@"21" name:@"古迹"],
                     [LTTheme initWith:@"22" name:@"赏花"],
                     [LTTheme initWith:@"23" name:@"动物乐园"],
                     [LTTheme initWith:@"24" name:@"植物园"],
                     [LTTheme initWith:@"25" name:@"采摘"],
                     [LTTheme initWith:@"26" name:@"红色旅游"],
                     [LTTheme initWith:@"27" name:@"民族风情"],
                     [LTTheme initWith:@"28" name:@"纪念馆"],
                     [LTTheme initWith:@"29" name:@"湖泊"],
                     [LTTheme initWith:@"30" name:@"溶洞"],
                     [LTTheme initWith:@"31" name:@"地质公园"],
                     [LTTheme initWith:@"32" name:@"城市观光"],
                     [LTTheme initWith:@"33" name:@"名人故居"],
                     [LTTheme initWith:@"34" name:@"海洋公园"],
                     [LTTheme initWith:@"35" name:@"博物馆"],
                     [LTTheme initWith:@"36" name:@"名窟石刻"],
                     [LTTheme initWith:@"37" name:@"影视基地"],
                     nil];*/
    self.themeArray=[NSArray arrayWithObjects:[LTTheme initWith:@"0" name:@"不限"],
                     [LTTheme initWith:@"21" name:@"赏花"],
                     [LTTheme initWith:@"22" name:@"水上乐园"],
                     [LTTheme initWith:@"20" name:@"海洋馆"],
                     [LTTheme initWith:@"4" name:@"漂流避暑"],
                     [LTTheme initWith:@"3" name:@"游船"],
                     [LTTheme initWith:@"9" name:@"农家乐园"],
                     [LTTheme initWith:@"11" name:@"登山探险"],
                     [LTTheme initWith:@"14" name:@"动植物园"],
                     [LTTheme initWith:@"12" name:@"山水园林"],
                     [LTTheme initWith:@"5" name:@"主题乐园"],
                     [LTTheme initWith:@"6" name:@"古镇山水"],
                     [LTTheme initWith:@"13" name:@"海岛度假"],
                     [LTTheme initWith:@"8" name:@"户外拓展"],
                     [LTTheme initWith:@"10" name:@"名胜古迹"],
                     [LTTheme initWith:@"16" name:@"影视基地"],
                     [LTTheme initWith:@"17" name:@"城市观光"],
                     [LTTheme initWith:@"15" name:@"博物馆"],
                     [LTTheme initWith:@"7" name:@"演出表演"],
                     [LTTheme initWith:@"1" name:@"温泉"],
                     [LTTheme initWith:@"19" name:@"文化宗教"],
                     [LTTheme initWith:@"2031408" name:@"采摘"],
                     [LTTheme initWith:@"2" name:@"滑雪"],
                     nil];
    _tableTheme=[[UITableView alloc]initWithFrame:CGRectMake(0, 0, _frame.size.width, _frame.size.height) style:UITableViewStylePlain];
    _tableTheme.delegate=self;
    _tableTheme.dataSource=self;
    [_tableTheme registerClass:[UITableViewCell class] forCellReuseIdentifier:@"reuse_themeCell"];
    [self addSubview:_tableTheme];
    //[_tableTheme reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; {
    return 1;
}
-(int)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _themeArray.count;
}
-(UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
 
    UILabel* lblHeader=[[UILabel alloc] init];
    
    lblHeader.textColor=[UIColor blueColor];
    lblHeader.backgroundColor=[UIColor colorWithRed:192.0/255.0f green:192.0f/255.0f blue:192.0f/255.0f alpha:0.5];
    lblHeader.text=@"请选择主题";
    return lblHeader;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"reuse_themeCell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    
    if(cell ==nil){
        cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]   ;
       // cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier: CMainCell] autorelease];
    }
    cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
    if( self.themeArray!=nil && self.themeArray.count>indexPath.row){
      LTTheme* theme=(LTTheme*)[self.themeArray objectAtIndex:indexPath.row];
    
       cell.textLabel.text=theme.themeName;
    }
    //cell.detailTextLabel.text=@"detail";
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if( self.themeArray!=nil && self.themeArray.count>indexPath.row){
        LTTheme* theme=(LTTheme*)[self.themeArray objectAtIndex:indexPath.row];
        
        if(self.delegate !=nil){
            [self.delegate themeDidSelection:theme.themeID themeName:theme.themeName];
        }
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
